<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增文件')"/>
    <th:block th:include="include :: bootstrap-fileinput-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-teachingMaterial-add">
        <div class="form-group">
            <label class="col-sm-3 control-label">文件说明：</label>
            <div class="col-sm-8">
                <input id="fileName" name="fileName" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">文件：</label>
            <div class="file-loading">
                <input name="url" id="fileinput-demo-1" type="file">
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: bootstrap-fileinput-js" />
<script type="text/javascript">
    var prefix = ctx + "edusystem/teachingMaterial";
    var fileName;
    var url;
    $("#form-teachingMaterial-add").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/add", "fileName="+fileName+"&url="+url);
        }
    }

    $(document).ready(function () {
        $("#fileinput-demo-1").fileinput({
            'theme': 'explorer-fas',
            'uploadUrl': prefix+"/update" ,
            overwriteInitial: false,
            initialPreviewAsData: true,
            maxFileCount:1,
        });
    });
    $("#fileinput-demo-1").on("fileuploaded", function(event, data, previewId, index) {
        console.log(data.files[0].name);
        console.log(data.response.msg);
        fileName = data.files[0].name;
        url = data.response.msg;
        $("#fileName").val(data.files[0].name);
    });
    // $('#fileinput-demo-1').on('filebatchuploadsuccess', function(event, data, previewId, index) {
    //     console.log(data)
    //     console.log(event)
    //     console.log(previewId)
    //     console.log(index)
    // });
</script>
</body>
</html>